{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Game Theory and Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Preface\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This handbook is an introduction to studying [Game Theory](https://en.wikipedia.org/wiki/Game_theory) with [Open-Source Software](https://en.wikipedia.org/wiki/Open-source_software).\n",
    "\n",
    "Game theory is concerned with conflicts, cooperation, and competition between individuals. It makes use of mathematical tools and logic.\n",
    "\n",
    "Game theory has grown into a complex and multi-branched subject over the years due to the applications it has offered to real world problems. It has provided scholars of mathematics, psycholy, politics, philosophy and  economics with a powerful tool for understanding a wide variety of problems for their disciplines.\n",
    "\n",
    "There are two main focuses of study in non cooperative Game Theory and there are various pieces of softwares for each discipline:\n",
    "\n",
    "1. The study of what is called a [Nash Equilibrium](https://en.wikipedia.org/wiki/Nash_equilibrium)\n",
    "    - Gambit (a piece of software with a Python interface): http://gambit.sourceforge.net/\n",
    "    - Cocalc.com (using Sagemath). Documentation: https://doc.sagemath.org/html/en/reference/game_theory/index.html\n",
    "    - Nashpy. Documentation: https://nashpy.readthedocs.io/en/latest/\n",
    "\n",
    "2. Iterated Games\n",
    "    - Axelrod Python library: https://github.com/Axelrod-Python/Axelrod\n",
    "\n",
    "In this workshop we will concern ourselves with the discipline of Iterated Games. Specifically, we will be using the Axelrod Python Library which will help us study an example known as the Iterated Prisoner's Dilemma (IPD).\n",
    "In the following sections, we will familiarize ourselves with the IPD and the library. Once we cover the basics\n",
    "we will try to dive a bit deeper in the library and the tournaments of the IPD."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Introduction to the Iterated Prisoner's Dilemma\n",
    "-----------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Prisoner's Dilemma is a two players game commonly studied in Game Theory. The story goes:\n",
    "\n",
    "\n",
    ">There are two criminals and they have been arrested by the police. The criminals are put in separate cells and have no way of communicating with each other.\n",
    "\n",
    ">Unfortunately for the police officer there are not enough evidence to convince the criminals for a serious crime but only for minor theft. The officer then comes up with a way to trick the two prisoners.\n",
    "\n",
    ">Simultaneously, the police officer offer each prisoner a bargain. Each prisoner is given the opportunity either to betray the other by testifying that the other committed the crime, or to cooperate with the other by remaining silent. The offer is:\n",
    "\n",
    ">If A and B each betray the other, each of them serves two years in prison.\n",
    "If A betrays B but B remains silent, A will be set free and B will serve three years in prison (and vice versa)\n",
    "If A and B both remain silent, both of them will only serve one year in prison (on the lesser charge).\n",
    "\n",
    "\n",
    "In game theory we represent such games using a matrix. Instead of months in prison we will be using a positive payoff (a gain) for each of the actions. See below:\n",
    "\n",
    "\n",
    "                              Prisoner A\n",
    "                         --------------------     \n",
    "                         |Cooperate| Defect |    \n",
    "               |---------|---------|--------|\n",
    "               |Cooperate| (3, 3)  | (0, 5) |\n",
    "    Prisoner B |---------|---------|--------|\n",
    "               | Defect  | (5, 0)  | (1, 1) |\n",
    "               ------------------------------\n",
    "\n",
    "\n",
    "Now let assume that the officer locks our two criminals back in prison and asks them the same question again the next day. Now let us assume that this is repeated for a given number of iterations. Then we have what is called the iterated prisoner's dilemma.\n",
    "\n",
    "The Axelrod library is used to model the IPD. It manages to do so by creating a tournament where different strategies, sets of rules, (implemented within the library) compete in a round robin tournament."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Summary\n",
    "--------\n",
    "\n",
    "This section has discussed:\n",
    "\n",
    "- Introduction to the iterated prisoner's dilemma.\n",
    "\n",
    "We will now move to the next section where we will look at matches and tournaments."
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "game-python",
   "language": "python",
   "name": "game-python"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
